Remove now unnecessary Rustc::blank method
authorAleksey Kladov <aleksey.kladov@gmail.com>
Fri, 15 Jul 2016 17:33:57 +0000 (20:33 +0300)
committerAleksey Kladov <aleksey.kladov@gmail.com>
Fri, 15 Jul 2016 17:35:38 +0000 (20:35 +0300)
src/cargo/util/rustc.rs
tests/version.rs

index aedf6e19c67abfdf835f7bf9627a7444039a5d16..51039de7acdfb8f5c2275aa7b2ab872b05ae4e6a 100644 (file)
@@ -5,11 +5,12 @@ use util::{self, CargoResult, internal, ChainError};
 pub struct Rustc {
     pub verbose_version: String,
     pub host: String,
+    /// Backwards compatibility: does this compiler support `--cap-lints` flag?
     pub cap_lints: bool,
 }
 
 impl Rustc {
-    /// Run the compiler at `path` to learn varioues pieces of information about
+    /// Run the compiler at `path` to learn various pieces of information about
     /// it.
     ///
     /// If successful this function returns a description of the compiler along
@@ -18,33 +19,32 @@ impl Rustc {
         let mut cmd = util::process(path.as_ref());
         cmd.arg("-vV");
 
-        let mut ret = Rustc::blank();
         let mut first = cmd.clone();
         first.arg("--cap-lints").arg("allow");
-        let output = match first.exec_with_output() {
-            Ok(output) => { ret.cap_lints = true; output }
-            Err(..) => try!(cmd.exec_with_output()),
+
+        let (cap_lints, output) = match first.exec_with_output() {
+            Ok(output) => (true, output),
+            Err(..) => (false, try!(cmd.exec_with_output())),
         };
-        ret.verbose_version = try!(String::from_utf8(output.stdout).map_err(|_| {
+
+        let verbose_version = try!(String::from_utf8(output.stdout).map_err(|_| {
             internal("rustc -v didn't return utf8 output")
         }));
-        ret.host = {
-            let triple = ret.verbose_version.lines().filter(|l| {
+
+        let host = {
+            let triple = verbose_version.lines().find(|l| {
                 l.starts_with("host: ")
-            }).map(|l| &l[6..]).next();
+            }).map(|l| &l[6..]);
             let triple = try!(triple.chain_error(|| {
                 internal("rustc -v didn't have a line for `host:`")
             }));
             triple.to_string()
         };
-        Ok(ret)
-    }
 
-    pub fn blank() -> Rustc {
-        Rustc {
-            verbose_version: String::new(),
-            host: String::new(),
-            cap_lints: false,
-        }
+        Ok(Rustc {
+            verbose_version: verbose_version,
+            host: host,
+            cap_lints: cap_lints,
+        })
     }
 }
index f15f1e2cda4a469d5b8f2af61af0b3d739c3096d..bc1040ed1856cfa71b0efa0a573cf49ea46b6e89 100644 (file)
@@ -55,4 +55,4 @@ fn version_works_without_rustc() {
     let p = project("foo");
     assert_that(p.cargo_process("version").env("PATH", ""),
                 execs().with_status(0));
-}
\ No newline at end of file
+}